local rolely_dingmin = fk.CreateSkill {
    name = "rolely_dingmin",
    tags = { Skill.Compulsory }

}
Fk:loadTranslationTable {
    ["rolely_dingmin"] = "定民",
    [":rolely_dingmin"] = "锁定技，每回合限一次，当你受到伤害后，你展示任意张花色各不相同的牌，随后你可以将这些牌交给一名角色，" ..
        "若你交出这些牌，你重复展示牌堆的顶牌，直到你因此展示牌的花色数等于你交出的牌数，然后你获得因此展示的牌。",

    ["$rolely_dingmin1"] = "人道朝善，诡道聚民！",
    ["$rolely_dingmin2"] = "以道驭术，以法灭阵！",
}
Fk:addPoxiMethod {
    name = "rolely_dingmin",
    prompt = "定民：请选择四张花色不同的牌",
    card_filter = function(to_select, selected, data)
        if #selected == 0 then
            return Fk:getCardById(to_select).suit ~= Card.NoSuit
        else
            return table.every(selected, function(id)
                return Fk:getCardById(to_select):compareSuitWith(Fk:getCardById(id), true)
            end)
        end
    end,
    feasible = function(selected)
        return #selected > 0
    end,
    default_choice = function(data, extra_data)
        return { data[1][2][1] }
    end,
}
rolely_dingmin:addEffect(fk.Damaged, {
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(rolely_dingmin.name) and player:getHandcardNum() > 0 and
            player:usedSkillTimes(rolely_dingmin.name, player.HistoryPhase) == 0
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local cards = room:askToPoxi(player, {
            poxi_type = rolely_dingmin.name,
            data = {
                { rolely_dingmin.name, player:getCardIds("h") },
            },
            cancelable = false,
        })
        if cards then
            player:showCards(cards)
            room:delay(600)
            local id = room:askToChoosePlayers(player, {
                targets = room:getOtherPlayers(player),
                min_num = 1,
                max_num = 1,
                prompt = "定民：是否将这些牌交给一名其他角色？",
                skill_name = rolely_dingmin.name,
                cancelable = true,
            })[1]
            if id then
                room:moveCardTo(cards, Card.PlayerHand, id, fk.ReasonPrey, rolely_dingmin.name, nil, true, player.id)
                local suits = {}
                local ids = {}
                while true do
                    local card = room:getNCards(1)
                    player:showCards(card)
                    room:delay(800)
                    table.insertIfNeed(suits, Fk:getCardById(card[1]):getSuitString())
                    room:turnOverCardsFromDrawPile(player, card, rolely_dingmin.name)
                    table.insert(ids, card[1])
                    if #suits >= #cards then
                        room:moveCardTo(ids, Card.PlayerHand, player, fk.ReasonPrey, rolely_dingmin.name, nil, true,
                            player.id)
                        break
                    end
                end
            end
        end
    end,
})
return rolely_dingmin
